package com.gxwy.shenzhou.message;

import com.gxwy.shenzhou.HeaderRequest;
import com.gxwy.shenzhou.SplitString;
import com.gxwy.shenzhou.StringHandler;
import com.gxwy.shenzhou.Supply;

public class ZhengCunZhengQuXiaoHuZhuanHuoQiRequest implements StringHandler{
private String zhdh;
private String pzdh;
private String qkfs;
private String mm;
private String ywdh;
private String xxh;
private String jyje;
private String kh;
private int reallon=0;
private static final int ZHDH_len=32;
private static final int PZDH_len=9;
private static final int QKFS_len=1;
private static final int MM_len=6;
private static final int YWDH_len=3;
private static final int XXH_len=3; 
private static final int JYJE_len=15;
private static final int KH_len=32;
private static final int TOTAL_LEN=ZHDH_len+PZDH_len+QKFS_len+MM_len+YWDH_len+XXH_len+JYJE_len+KH_len;

private static final int ZHDH_FLAG=1;
private static final int PZDH_FLAG=1;
private static final int QKFS_FLAG=1;
private static final int MM_FLAG=1;
private static final int YWDH_FLAG=1;
private static final int XXH_FLAG=1;
private static final int JYJE_FLAG=1;
private static final int KH_FLAG=1;


private HeaderRequest header=new HeaderRequest(true);



public HeaderRequest getHeader() {
	return header;
}

public void setHeader(HeaderRequest header) {
	this.header = header;
}

public String getZhdh() {
	return zhdh;
}

public void setZhdh(String zhdh) throws Exception {
	if(zhdh==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(zhdh.getBytes("gbk").length<ZHDH_len){
	   
		this.zhdh=Supply.supply(zhdh,ZHDH_FLAG,ZHDH_len);
	}else if(zhdh.getBytes("gbk").length>ZHDH_len){
		 Exception e=new Exception("Too long");
		 throw e;
	}else{
		this.zhdh = zhdh;			
	}}

public String getPzdh() {
	return pzdh;
}


public void setPzdh(String pzdh) throws Exception{
	if(pzdh==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(pzdh.getBytes("gbk").length<PZDH_len){
   
		this.pzdh=Supply.supply(pzdh,PZDH_FLAG,PZDH_len);
	}else if(pzdh.getBytes("gbk").length>PZDH_len){
		 Exception e=new Exception("Too long");
		 e.printStackTrace();
	}else{
		this.pzdh = pzdh;			
	}
}

public String getQkfs() {
	return qkfs;
}

public void setQkfs(String qkfs) throws Exception{
	if(qkfs==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(qkfs.getBytes("gbk").length<QKFS_len){
	
		this.qkfs=Supply.supply(qkfs,QKFS_FLAG,QKFS_len);
	}else if(qkfs.getBytes("gbk").length>QKFS_len){
		 Exception e=new Exception("Too long");
		 e.printStackTrace();
	}else{
		this.qkfs =qkfs;			
	}
}

public String getMm() {
	return mm;
}

public void setMm(String mm) throws Exception{
	if(mm==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(mm.getBytes("gbk").length<MM_len){
	
		this.mm=Supply.supply(mm,MM_FLAG,MM_len);
	}else if(mm.getBytes("gbk").length>MM_len){
		 Exception e=new Exception("Too long");
		 e.printStackTrace();
	}else{
		this.mm =mm;			
	}
}

public String getYwdh() {
	return ywdh;
}

public void setYwdh(String ywdh)  throws Exception{
	if(ywdh==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(ywdh.getBytes("gbk").length<YWDH_len){
	
		this.ywdh=Supply.supply(ywdh,YWDH_FLAG,YWDH_len);
	}else if(ywdh.getBytes("gbk").length>YWDH_len){
		 Exception e=new Exception("Too long");
		 e.printStackTrace();
	}else{
		this.ywdh =ywdh;			
	}
}

public String getXxh() {
	return xxh;
}

public void setXxh(String xxh)  throws Exception{
	if(xxh==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(xxh.getBytes("gbk").length<XXH_len){
		
		this.xxh=Supply.supply(xxh,XXH_FLAG,XXH_len);
	}else if(xxh.getBytes("gbk").length>XXH_len){
		 Exception e=new Exception("Too long");
		 e.printStackTrace();
	}else{
		this.xxh =xxh;			
	}
}

public String getJyje() {
	return jyje;
}

public void setJyje(String jyje)  throws Exception{
	if(jyje==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(jyje.getBytes("gbk").length<JYJE_len){
	
		this.jyje=Supply.supply(jyje,JYJE_FLAG,JYJE_len);
	}else if(jyje.getBytes("gbk").length>JYJE_len){
		 Exception e=new Exception("Too long");
		 e.printStackTrace();
	}else{
		this.jyje =jyje;			
	}
}

public String getKh() {
	return kh;
}
public void setKh(String kh)   throws Exception{
	if(kh==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(kh.getBytes("gbk").length<KH_len){
	
		this.kh=Supply.supply(kh,KH_FLAG,KH_len);;
	}else if(kh.getBytes("gbk").length>KH_len){
		 Exception e=new Exception("Too long");
		 e.printStackTrace();
	}else{
		this.kh =kh;			
	}
}
public String build () throws Exception{
	if(this.getHeader()==null){
		throw new Exception("Header is null");
	}

	if(this.getZhdh()==null){
		this.setZhdh("");
	}
    if(this.getPzdh()==null){
    	this.setPzdh("");
    }
    if(this.getQkfs()==null){
    	this.setQkfs("");
    }
    if(this.getMm()==null){
    	this.setMm("");
    }
    if(this.getYwdh()==null){
    	this.setYwdh("");
    }
    if(this.getXxh()==null){
    	this.setXxh("");
    }
    if(this.getJyje()==null){
    	this.setJyje("");
    }
    if(this.getKh()==null){
    	this.setKh("");
    }
    Integer totallen=header.TOTAL_LEN+TOTAL_LEN-HeaderRequest.LEN_LEN;
    this.getHeader().setLen(totallen.toString());
   return this.getHeader().build()+this.getZhdh()+this.getPzdh()+this.getQkfs()+this.getMm()+this.getYwdh()+this.getXxh()+this.getJyje()+this.getKh();
   }

public void parse(String str) throws Exception{
	
	if(str==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(str.getBytes("gbk").length<TOTAL_LEN+header.TOTAL_LEN){
		Exception e=new Exception("Header is null");
		e.printStackTrace();
	}else{
		String headerLen=SplitString.splitString(str,reallon, reallon+header.TOTAL_LEN);
		reallon+=header.TOTAL_LEN;
		header.parse(headerLen);	
		this.setZhdh(SplitString.splitString(str,reallon,reallon+ZHDH_len));
		reallon+=ZHDH_len;
		this.setPzdh(SplitString.splitString(str,reallon,reallon+PZDH_len));
		reallon+=PZDH_len;
		this.setQkfs(SplitString.splitString(str,reallon,reallon+QKFS_len));
		reallon=reallon+QKFS_len;
		this.setMm(SplitString.splitString(str,reallon,reallon+MM_len));
		reallon=reallon+MM_len;
		this.setMm(SplitString.splitString(str,reallon,reallon+YWDH_len));
	    reallon+=YWDH_len;
	    this.setYwdh(SplitString.splitString(str,reallon,reallon+XXH_len));
	    reallon+=XXH_len;
	    this.setJyje(SplitString.splitString(str,reallon,reallon+JYJE_len));
	    reallon+=JYJE_len;
	    this.setKh(SplitString.splitString(str,reallon,reallon+KH_len));
	}
	
}
public static void main(String args[]) throws Exception{
	ZhengCunZhengQuXiaoHuZhuanHuoQiRequest a=new ZhengCunZhengQuXiaoHuZhuanHuoQiRequest();
	System.out.println(a.TOTAL_LEN);
    a.setJyje("1");
    a.setKh("2");
    a.setMm("3");
    a.setPzdh("4");
    a.setQkfs("5");
    a.setJyje("6");
   a.parse( a.build());
   if(a.getJyje().trim().equals("1")){
	   System.out.println("jyjeyes");
   }
   if(a.getKh().trim().equals("2")){
	   System.out.println("KHyes");
   }
   if(a.getMm().trim().equals("3")){
	   System.out.println("Mmyes");
   }
   if(a.getPzdh().trim().equals("4")){
	   System.out.println("pzdhyes");
	      }
   if(a.getQkfs().trim().equals("5")){
	   System.out.println("Qkfsyes");
   }
   if(a.getJyje().trim().equals("6")){
	   System.out.println("jyjeyes");
   }
  System.out.println(a.getJyje()) ;
  System.out.println(a.getKh());
  System.out.println(a.getMm());
  System.out.println(a.getPzdh());
  System.out.println(a.getJyje());
  

}
}
